package com.czp.mall.order.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import com.czp.mall.order.pojo.Order;
import com.czp.mall.order.service.OrderService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;

@RestController
public class OrderController {

	
	@Autowired
	private OrderService orderService;
	
	@GetMapping(value = "/order/{id}",produces = {"application/json;charset=UTF-8"})
	@HystrixCommand(fallbackMethod = "defaultQueryOrder" ,commandProperties = {
			// commandProperties线程隔离配置，平常不需要配置，出问题再配置即可
			@HystrixProperty(name = "execution.isolation.strategy", value = "SEMAPHORE") 
	}) // 添加回调
	public Order queryOrderById(@PathVariable(name = "id") String id) {
		return orderService.queryOrderById(id);
	}
	
	
	/**
	 * 回调的方法要和原方法的返回值还有接收参数一致
	 */
	public Order defaultQueryOrder(String id) {
		return new Order("0", null, null, null, null);
	}
}
